/*zA55aoHexmQNw+wGMcURwnb9hMcA9d3uO+17gDEOEGjbn9Vp6v2Zyuc3x9tT9SMz*/
/*
 * @Author: xiahui 
 * @PageInfo: 卡片表体删行 
 * @Date: 2019-01-14 15:59:29 
 * @Last Modified by: xiahui
 * @Last Modified time: 2019-07-26 11:38:10
 */
import { BUTTONID, AREA } from '../../constance';
import { resetShoworderValue } from '../../utils/cardPageUtil';

export default function(props, moduleId, record, index) {
	if (record && index >= 0) {
		// 列操作
		props.cardTable.delRowsByIndex(moduleId, index);
		// 按钮可用性
		if (props.cardTable.getNumberOfRows(moduleId) > 0) {
			let checkArr = props.cardTable.getCheckedRows(moduleId);
			if (!checkArr || checkArr.length < 1) {
				props.button.setDisabled(getHeadButtonIds(moduleId), true);
			} else {
				props.button.setDisabled(getHeadButtonIds(moduleId), false);
			}
		}
	} else {
		// 肩操作
		let checkArr = props.cardTable.getCheckedRows(moduleId);
		let rowIndexes = [];
		if (checkArr && checkArr.length > 0) {
			checkArr.forEach((row) => {
				rowIndexes.push(row.index);
			});
			props.cardTable.delRowsByIndex(moduleId, rowIndexes);
			// 按钮可用性
			props.button.setDisabled(getHeadButtonIds(moduleId), true);
		}
	}
	resetShoworderValue(props, moduleId);
}

function getHeadButtonIds(moduleId) {
	let buttonIds;

	switch (moduleId) {
		case AREA.cardTableId:
			buttonIds = [ BUTTONID.DeleteLine, BUTTONID.CopyLine, BUTTONID.LinkPriceInfo ];
			break;
		case AREA.cardTermId:
			buttonIds = [ BUTTONID.DeleteLineTerm, BUTTONID.CopyLineTerm ];
			break;
		case AREA.cardPayId:
			buttonIds = [ BUTTONID.DeleteLinePay, BUTTONID.CopyLinePay ];
			break;
		case AREA.cardFeeId:
			buttonIds = [ BUTTONID.DeleteLineFee, BUTTONID.CopyLineFee ];
			break;
		case AREA.cardMemoraId:
			buttonIds = [ BUTTONID.DeleteLineMemora, BUTTONID.CopyLineMemora ];
			break;
	}

	return buttonIds;
}

/*zA55aoHexmQNw+wGMcURwnb9hMcA9d3uO+17gDEOEGjbn9Vp6v2Zyuc3x9tT9SMz*/